<?php if($this->layout == 'popup')
{
	echo $html->css('admin');	
	?>
<style type="text/css">
body,html{background:none;}</style>
<?php }?>
<h2><?php echo __("Define Filter")?></h2>
<?php 
if(!isset($saved))
{
	$editorReview = cr('GeneralConfig.disable_editor_reviews');
	echo $form->create('ContentScope', array('id' => 'add','url'=>"/".$this->params['url']['url']));
	echo $form->inputs(array('fieldset' => false), null, 'add');
	echo $form->end(__('Submit'));
	?>
	<script type="text/javascript">
	$(document).ready(function()
	{
		var editorReviewDisabled = "<?php echo $editorReview?>";
		updateConditions('#ContentScopeModel',null,editorReviewDisabled);
		$($(".addAnotherField").parent()).bind('afterTemplateInsert',function()
		{
			updateConditions('#ContentScopeModel',null,editorReviewDisabled);
		});
		$('#ContentScopeModel').bind('beforeFetchingOptions',function(field)
		{
			updateConditions(this,null,editorReviewDisabled);
		});	
		
	});
	
	function updateConditions(selector,selectedModel,editorReviewDisabled)
	{
		defaultConditionFieldHtml = '<option value=""><?php echo __("-Select-")?></option><option value="list_category_id"><?php echo __("Category")?></option><option value="is_featured"><?php echo __("Featured")?></option><option value="is_editorial"><?php echo __("Editorial")?></option>';
		if(editorReviewDisabled == 1)
		{
			defaultConditionFieldHtml = '<option value=""><?php echo __("-Select-")?></option><option value="list_category_id"><?php echo __("Category")?></option><option value="is_featured"><?php echo __("Featured")?></option>';
		}
		selectedModel = $(selector).val();		
		if(selectedModel == 'User')
		{
			$('#ContentScopeConditions').parent().hide();
		}else if(selectedModel == 'ReviewComment')
		{
			html = '<option value=""><?php echo __("-Select-")?></option><option value="list_category_id"><?php echo __("Category")?></option>';
			updateConditionFieldHtml(html);	
		}else
		{
			updateConditionFieldHtml(defaultConditionFieldHtml);
		}		
		
	}

	function updateConditionFieldHtml(html)
	{
		$('#ContentScopeConditions').parent().show();
		$('.fieldWrap').find('div .contentScopeConditionField').each(function()
		{
			if(html)
			{
				prevSelectedValue = $(this).val();				
				$(this).html(html);
				if(prevSelectedValue)
				{
					$(this).val(prevSelectedValue);
				}
			}
		});
	}

	</script>
	<?php 
}else{?>
<script type="text/javascript">
opener.updateOptionsNow("<?php echo $this->data['ContentScope']['model']?>");
self.close();
</script>
<?php }?>